// import e from "express";
import Vue from "vue";
import VueRouter from "vue-router";
import store from '../store/index'
Vue.use(VueRouter);

const routes = [{
        path: '/',
        redirect: '/index'
    },
    {
        path: '/index',
        name: 'index',
        component: () =>
            import ('../views/index.vue'),
    },
    {
        path: '/tiaozhan',
        name: 'tiaozhan',
        component: () =>
            import ('../views/tiaozhan.vue'),
    },
    {
        path: '/tieziDetail',
        name: 'tieziDetail',
        component: () =>
            import ('../views/tieziDetail.vue'),
    },
    {
        path: '/mytiexi',
        name: 'mytiexi',
        component: () =>
            import ('../views/mytiexi.vue'),
    },
    {
        path: '/luntan',
        name: 'luntan',
        component: () =>
            import ('../views/luntan.vue'),
    },
    {
        path: '/xuanhuan',
        name: 'xuanhuan',
        component: () =>
            import ('../views/xuanhuan.vue'),
    },
    {
        path: '/cart',
        name: 'cart',
        component: () =>
            import ('../views/cart.vue'),
    },
    {
        path: '/dizhi',
        name: 'dizhi',
        component: () =>
            import ('../views/dizhi.vue'),
    },
    {
        path: '/order',
        name: 'order',
        component: () =>
            import ('../views/order.vue'),
    },
    {
        path: '/dingdan',
        name: 'dingdan',
        component: () =>
            import ('../views/dingdan.vue'),
    },
    {
        path: '/xiangqing',
        name: 'xiangqing',
        component: () =>
            import ('../views/xiangqing.vue'),
    },
];

const router = new VueRouter({
    mode: "history",
    base: process.env.BASE_URL,
    routes,
});
router.beforeEach((to, from, next) => {
    if (store.state.user.id) {
        next()

    } else {
        if (to.path == "/index") {
            next()
        } else {
            store.commit("show", true)
        }
    }
    console.log(to);
})
export default router;